<?php

if (!empty($is_ajax)) {
    ?><div><?php
    ?><hr /><?php
    ?><br /><?php
}

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

$filter_block_control_class = 'filter_block_control';

$candidateModelName = 'Candidate';
$candidate_po_domain = 'candidates';

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/"), 'onclick_callback' => @$onclick_callback, 'without_form' => !empty($is_ajax)));?><?php
	$filterBlock->add(
        $form->label('candidate_group_id', __d('candidates', 'candidate_group_id_filter', true).': ', array('class'=>'filter')).
		$form->select('candidate_group_id', $candidate_groups_list, null, array('label' => false, 'class' => $filter_block_control_class))
	);
	if (Auth::o()->is('admin') || Auth::o()->is('ARCHIVE')) {
    	$filterBlock->add(
            $form->label('archived', __d('candidates', 'archived_filter', true).': ', array('class'=>'filter')).
    		$form->select('archived', $archived_list, null, array('label' => false, 'class' => $filter_block_control_class))
    	);
	}
	$filterBlock->add(
        $form->label('searche', __d(null, 'searche_filter', true).': ', array('class'=>'filter')).
		$form->text('searche', array('size' => '17', 'class' => $filter_block_control_class))
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

$json_array_rows = array();

if (count($list->rows)) {

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'surname', 'domain' => $candidate_po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'name', 'domain' => $candidate_po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'group', 'domain' => $candidate_po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'email', 'domain' => $candidate_po_domain));?><?php
        ?></th><?php
        if (Auth::o()->is('admin') || Auth::o()->is('ARCHIVE')) {
            ?><th class="nw"><?php
                ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'archived', 'domain' => $candidate_po_domain, 'msg' => 'archived_field'));?><?php
            ?></th><?php
        }
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'test_name', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'pass_date', 'domain' => $po_domain));?><?php
        ?></th><?php
        if (!empty($is_ajax)) {
            ?><th class="actions nw"></th><?php
        }
    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=$item[$candidateModelName]['surname'];?><?php
                ?> / <?php
                ?><?=$item[$candidateModelName]['surname_latin'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=$item[$candidateModelName]['name'];?><?php
                ?> / <?php
                ?><?=$item[$candidateModelName]['name_latin'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=$item[$candidateModelName]['Group']['name'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=$item[$candidateModelName]['email'];?><?php
            ?></td><?php
            if (Auth::o()->is('admin') || Auth::o()->is('ARCHIVE')) {
        		?><td class="nw"><?php
                    ?><?=h($archived_list[$item[$candidateModelName]['archived']]);?><?php
                ?></td><?php
            }
    		?><td class="nw"><?php
                ?><?=$item['Test']['name'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=Date::Short(DATE::SQL2UNIX($item['Testing']['pass_date']));?><?php
            ?></td><?php
            if (!empty($is_ajax)) {
                ?><td class="actions nw"><?php
                    ?><span id="testing_id_<?=$item['Testing']['id'];?>" class="testings_for_select"><?php
                    ?></span><?php
                ?></td><?php
            }
    	?></tr><?php

    	if (!empty($is_ajax)) {
        	$json_item = array();
        	$json_item["id"] = $item['Testing']['id'];
        	$json_item["surname_html"] = $item[$candidateModelName]['surname'] . ' / ' . $item[$candidateModelName]['surname_latin'];
        	$json_item["name_html"] = $item[$candidateModelName]['name'] . ' / ' . $item[$candidateModelName]['name_latin'];
        	$json_item["group_html"] = $item[$candidateModelName]['Group']['name'];
            if (Auth::o()->is('admin') || Auth::o()->is('ARCHIVE')) {
        	   $json_item["archived_html"] = h($archived_list[$item[$candidateModelName]['archived']]);
            }
        	$json_item["test_name_html"] = $item['Test']['name'];
        	$json_item["pass_date_html"] = Date::Short(DATE::SQL2UNIX($item['Testing']['pass_date']));


        	$json_array_rows[] = $json_item;
    	}
    }

?></tbody><?php
?></table><?php

vendor('json');

if (!empty($is_ajax)) {
    ?><?=$javascript->codeBlock('__ToolGUIEnv.putCandidatesList('.json::drawToComment($json_array_rows).');');?><?php
}
?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'completed_testings_List is empty', true);?><?php
    ?></span><?php
}

if (!empty($is_ajax)) {
    ?><hr /><?php
    ?></div><?php
}

?>